package com.zhuoyue.bquser.controller;

import com.zhuoyue.bquser.dto.ResponseResult;
import com.zhuoyue.bquser.entity.BqUserPO;
import com.zhuoyue.bquser.service.BqUserService;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    private final BqUserService bqUserService;

    public UserController(BqUserService bqUserService){
        this.bqUserService = bqUserService;
    }


    @PostMapping("/user")
    public ResponseResult<Object> save(BqUserPO bqUserPO){
        boolean save = bqUserService.save(bqUserPO);
        if (save){
            return ResponseResult.success("用户新增成功");
        }else {
            return ResponseResult.fail(1,"用户新增失败");
        }
    }

    @GetMapping("/user/${id}")
    public ResponseResult<Object> get(@PathVariable("id") Integer id){
        BqUserPO user = bqUserService.getById(id);
        if (null != user){
            return ResponseResult.success(user);
        }else {
            return ResponseResult.fail(1,"用户不存在");
        }
    }



}
